Ext.ns('WaterAbnormalView');

WaterAbnormalView = Ext.extend(Ext.Panel, {
	// 头部工具栏
	topbar : null,
	// 数据展示Panel
	gridPanel : null,
	// GridPanel的数据Store
	store : null,
	// 构造函数
	constructor : function(_cfg) {
		Ext.applyIf(this, _cfg);
		// 初始化组件
		this.initUIComponents();
		// 调用父类构造
		WaterAbnormalView.superclass.constructor.call(this, {
					id : 'WaterAbnormalView',
					title : '异常数据处理',
					region : 'center',
					layout : 'border',
					items : [this.searchPanel, this.gridPanel]
				});
	},// end of constructor

	// 初始化组件
	initUIComponents : function() {
		// 初始化搜索条件Panel
		this.searchPanel = new Ext.FormPanel({
					id : 'WaterAbnormalSearchForm',
					height : 100,
					region : 'north',
					frame : false,
					border : false,
					padding : '10',
					layout : 'column',
					title : '查询条件',
					labelWidth : 60,
					enctype : 'multipart/form-data',
					fileUpload : true,
					url : __ctxPath + '/pdaweb/checkXLSFormatPdaWaterList.do',
					layoutConfig : {
						padding : '5',
						align : 'middle'
					},
					defaults : {
						columnWidth : 0.33,
						layout : 'form',
						border : false,
						style : 'padding-left:10px;',
						defaults : {
							xtype : 'textfield',
							width : 100
						}
					},
					items : [{
								items : [{
											fieldLabel : '抄表年月',
											xtype : 'monthfield',
											value : new Date(),
											editable : false,
											allowblank : false,
											name : 'Q_month_S_LK'
										}, {
											fieldLabel : '区  ID',
											name : 'Q_pdaWaterMeter.districtId_S_LK'
										}]
							}, {
								items : [{
											fieldLabel : '水表编号',
											name : 'Q_amId_S_EQ'
										}, {
											fieldLabel : '栋     ID',
											name : 'Q_pdaWaterMeter.buildingId_S_LK'
										}]
							}, {
								items : [{
											fieldLabel : '房     ID',
											name : 'Q_pdaWaterMeter.aparmentId_S_LK'
										}]
							},{
								items : [{
											xtype:'hidden',
											name : 'Q_status_S_IN',
											value: '2,3,4'
				                         },{
                                            xtype:'hidden',
                                            name : 'Q_degree_L_NEQ',
                                            value: '0'
                                         }]
							}]
				});// end of the searchPanel

		this.store = new Ext.data.JsonStore({
					url : __ctxPath + '/pdaweb/listPdaWaterList.do',
					root : 'result',
					totalProperty : 'totalCounts',
					fields : [{
								name : 'id',
								type : 'int'
							}, 'status', 'amId', 'lastDegree', 'degree',
							'pdaWaterMeter.districtId',
							'pdaWaterMeter.buildingId',
							'pdaWaterMeter.aparmentId', 'recorderId', 'month']
				});// end of the store
		this.store.setDefaultSort('status', 'desc');
		
		
		var sm = new Ext.grid.CheckboxSelectionModel({
					handleMouseDown : Ext.emptyFn
		});
		var cm = new Ext.grid.ColumnModel({
			columns : [new Ext.grid.RowNumberer(), {
						header : '水表编号',
						dataIndex : 'amId'
					}, {
						header : '上月读数',
						width : 65,
						dataIndex : 'lastDegree',
						renderer : function(val) {
							return val == -1 ? "" : val;
						}
					}, {
						header : '读数',
						width : 65,
						dataIndex : 'degree'
					}, {
						header : '区 ID',
						dataIndex : 'pdaWaterMeter.districtId'
					}, {
						header : '栋 ID',
						dataIndex : 'pdaWaterMeter.buildingId'
					}, {
						header : '房 ID',
						dataIndex : 'pdaWaterMeter.aparmentId'
					}, {
						header : '抄表人',
						width : 80,
						dataIndex : 'recorderId'
					}, {
						header : '抄表年月',
						width : 60,
						dataIndex : 'month'
					}, {
						header : '管理',
						dataIndex : 'id',
						width : 50,
						sortable : false,
						renderer : function(value, metadata, record, rowIndex,
								colIndex) {
							var d = record.data;
							var recordStr = d.amId + ";" + d.lastDegree + ";"
									+ d.degree + ";"
									+ record.get("pdaWaterMeter.districtId")
									+ ";"
									+ record.get("pdaWaterMeter.buildingId")
									+ ";"
									+ record.get("pdaWaterMeter.aparmentId")
									+ ";" + (d.recorderId==null?"":d.recorderId)+ ";" + d.month + ";"
									+ d.status;

							return '&nbsp;<button title="编辑" value=" " class="btn-edit" '
									+ 'onclick="WaterAbnormalView.edit('
									+ record.data.id
									+ ",\'"
									+ recordStr
									+ '\');">&nbsp</button>';
						}
					}],
			defaults : {
				menuDisabled : false,
				width : 120
			}
		});// end of the cm

		this.topbar = new Ext.Toolbar({
					height : 30,
					bodyStyle : 'text-align:left',
					items : [new Ext.Button({
								iconCls : 'search',
								text : '查询',
								handler : function() {
									var searchPanel = Ext
											.getCmp('WaterAbnormalSearchForm');
									var gridPanel = Ext
											.getCmp('WaterAbnormalGrid');
									if (searchPanel.getForm().isValid()) {
										$search({
													searchPanel : searchPanel,
													gridPanel : gridPanel
												});
									}
								}
							})]
				});

		this.gridPanel = new Ext.grid.GridPanel({
					id : 'WaterAbnormalGrid',
					tbar : this.topbar,
					region : 'center',
					store : this.store,
					trackMouseOver : true,
					disableSelection : false,
					loadMask : true,
					autoHeight : true,
					cm : cm,
					sm : sm,
					viewConfig : {
						showPreview : false,
						getRowClass : function(record, rowIndex, rowParams,
								store) {// 异常状态
							var status = record.data.status;
							if ('2' == status) {
								return 'x-grid-record-error';
							} else if ('3' == status || '4' == status) {
								return 'x-grid-record-warning';
							} else {
								return '';
							}
						}
					},
					listeners:{
						'click' : Ext.emptyFn
					},
					bbar : new Ext.PagingToolbar({
								pageSize : 25,
								store : this.store,
								displayInfo : true,
								displayMsg : '当前显示从{0}至{1}， 共{2}条记录',
								emptyMsg : "当前没有记录"
							})
				});

		var gridPanel = this.gridPanel;
	}
});

// 编辑
WaterAbnormalView.edit = function(recId, recordStr) {
	new WaterAbnormalForm({
				recId : recId,
				recordStr : recordStr
			}).show();
};
